﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Landscape.Business.Common
{
    public class LandscapeEventArgs : EventArgs
    {
        Dictionary<string, object> _objectsToSend = new Dictionary<string,object>();

        private LandscapeEventArgs()
        {

        }

        public LandscapeEventArgs(string pUniqueName, object pObjectToSend)
        {
            _objectsToSend.Add(pUniqueName, pObjectToSend);
        }

        public void RemoveObject(string pUniqueName)
        {
            if (_objectsToSend.ContainsKey(pUniqueName))
            {
                _objectsToSend.Remove(pUniqueName);   
            }
        }

        public void AddObject(string pUniqueName, object pObjectToSend)
        {
            if (!_objectsToSend.ContainsKey(pUniqueName))
            {
                _objectsToSend.Add(pUniqueName, pObjectToSend);
            }
            else
            {
                _objectsToSend[pUniqueName] = pObjectToSend;
            }
        }

        public bool Exists(string pUniqueName)
        {
            return _objectsToSend.ContainsKey(pUniqueName);
        }

        /// <summary>
        /// Returns the value of given key
        /// Use TAB_NO to return the current active tab id.
        /// </summary>
        /// <param name="pUniqueName">KEY to look for</param>
        /// <returns>Value associated with the give key</returns>
        public object GetValue(string pUniqueName)
        {
            if (Exists(pUniqueName))
            {
                return _objectsToSend[pUniqueName];
            }
            else
            {
                throw new LandscapeException("No object found with the unique name.");
            }
        }       

        public int GetEventTabNo()
        {
            return Convert.ToInt32(this.GetValue("TAB_NO"));
        }
    }
}